package com.bjsxt.controller;

import com.bjsxt.dto.LoginFormDto;
import com.bjsxt.model.LoginUserResultVo;
import com.bjsxt.model.Result;
import com.bjsxt.service.LoginService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description:
 * 登录的控制层
 *
 * @author ALIENWARE <br />
 * @date 2021/9/6
 */
@RestController
@RequestMapping
@Api(tags = "登录的控制器")
public class LoginController {

    /**
     * 会员登录业务层接口
     */
    @Autowired
    private LoginService loginService;

    /**
     * 会员登录
     *
     * @param loginFormDto 会员登录数据传输对象
     * @return 统一响应对象
     */
    @PostMapping("/login")
    // @PreAuthorize("hasAuthority('notice_update')")
    @ApiOperation(value = "会员登录", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loginFormDto", value = "会员登录数据 的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<LoginUserResultVo> login(@RequestBody @Validated LoginFormDto loginFormDto) {
        // 调用业务层代码, 进行登录操作
        LoginUserResultVo loginUserResultVo = loginService.login(loginFormDto);
        // 返回响应数据
        return Result.success(loginUserResultVo);
    }
}
